from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet

from apps.goods.models import SpecificationOption,SPUSpecification
from apps.meiduo_admin.serializers.option import SpecificationOptionSerializer, SPUSpecificationSerializer
from apps.meiduo_admin.utils import PageNum


class SpecificationOptionView(ModelViewSet):
    """
    规格选项表管理
    """
    serializer_class = SpecificationOptionSerializer
    queryset = SpecificationOption.objects.all()
    pagination_class = PageNum

    # 获取规格信息
    def specs(self,request):
        # 获取所有规格
        data = SPUSpecification.objects.all()
        # 返回规格数据
        ser = SPUSpecificationSerializer(data,many=True)
        return Response(ser.data)
